package com.xoms.admin.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.admin.controller.res.*;
import com.xoms.admin.controller.res.bean.*;
import com.xoms.admin.controller.springmvc.req.*;

/**
 * 商品增库存相关接口
 **/
@Controller
@RequestMapping(value = "/store", produces = "application/json")
public class SProStockController {
	@Autowired
	com.xoms.admin.controller.ProStockController proStockController;

	/**
	 * 获取商仓库\柜台列表
	 **/
	@RequestMapping("/v1/getStores")
	@ResponseBody
	public ListResult<RProStoreBean> getStores(@Validated GetProStoresParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProStoreBean> res = new ListResult<RProStoreBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getStores(param, request, response);
	}

	/**
	 * 新建、编辑柜台仓库
	 **/
	@RequestMapping("/v1/editStore")
	@ResponseBody
	public ObjectResult<RProStoreBean> editStore(@Validated EditProStoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProStoreBean> res = new ObjectResult<RProStoreBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.editStore(param, request, response);
	}

	/**
	 * 删除柜台仓库信息
	 **/
	@RequestMapping("/v1/delStore")
	@ResponseBody
	public BaseResult delStore(@Validated DelProStoreParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.delStore(param, request, response);
	}

	/**
	 * 获取供应商列表
	 **/
	@RequestMapping("/v1/getProvider")
	@ResponseBody
	public ListResult<RProviderBean> getProvider(@Validated GetProviderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProviderBean> res = new ListResult<RProviderBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getProvider(param, request, response);
	}

	/**
	 * 新建、编辑供应商
	 **/
	@RequestMapping("/v1/editProvider")
	@ResponseBody
	public ObjectResult<RProviderBean> editProvider(@Validated EditProviderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProviderBean> res = new ObjectResult<RProviderBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.editProvider(param, request, response);
	}

	/**
	 * 删除供应商信息
	 **/
	@RequestMapping("/v1/delProvider")
	@ResponseBody
	public BaseResult delProvider(@Validated DelProviderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.delProvider(param, request, response);
	}

	/**
	 * 商品库存列表，根据仓库获取商品列表及数量
	 **/
	@RequestMapping("/v1/getProStocks")
	@ResponseBody
	public ListResult<RProStockBean> getProStocks(@Validated GetProStocksParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProStockBean> res = new ListResult<RProStockBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getProStocks(param, request, response);
	}

	/**
	 * 采购-获取列表
	 **/
	@RequestMapping("/v1/getPurchases")
	@ResponseBody
	public ListResult<RPurchaseBean> getPurchases(@Validated GetPurchasesParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RPurchaseBean> res = new ListResult<RPurchaseBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getPurchases(param, request, response);
	}

	/**
	 * 采购-获取详情列表
	 **/
	@RequestMapping("/v1/getPurchaseDetails")
	@ResponseBody
	public ListResult<RPurchaseInfoBean> getPurchaseDetails(@Validated GetPurchaseDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RPurchaseInfoBean> res = new ListResult<RPurchaseInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getPurchaseDetails(param, request, response);
	}

	/**
	 * 采购-新建、编辑
	 **/
	@RequestMapping("/v1/editPurchase")
	@ResponseBody
	public ObjectResult<RPurchaseBean> editPurchase(@Validated EditPurchaseParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RPurchaseBean> res = new ObjectResult<RPurchaseBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.editPurchase(param, request, response);
	}

	/**
	 * 采购-删除采购单
	 **/
	@RequestMapping("/v1/delPurchase")
	@ResponseBody
	public BaseResult delPurchase(@Validated DelPurchaseParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.delPurchase(param, request, response);
	}

	/**
	 * 采购-提交审核
	 **/
	@RequestMapping("/v1/submitPurchase")
	@ResponseBody
	public BaseResult submitPurchase(@Validated SubPurchaseParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.submitPurchase(param, request, response);
	}

	/**
	 * 入库-获取列表
	 **/
	@RequestMapping("/v1/getStockIns")
	@ResponseBody
	public ListResult<RProStockInBean> getStockIns(@Validated GetStockInsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProStockInBean> res = new ListResult<RProStockInBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getStockIns(param, request, response);
	}

	/**
	 * 入库-获取详情列表
	 **/
	@RequestMapping("/v1/getStockInDetails")
	@ResponseBody
	public ListResult<RProStockInInfoBean> getStockInDetails(@Validated GetStockInDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProStockInInfoBean> res = new ListResult<RProStockInInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.getStockInDetails(param, request, response);
	}

	/**
	 * 入库-采购入库
	 **/
	@RequestMapping("/v1/insertStockIn")
	@ResponseBody
	public ObjectResult<RProStockInBean> insertStockIn(@Validated Purchase4StockInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProStockInBean> res = new ObjectResult<RProStockInBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.insertStockIn(param, request, response);
	}

	/**
	 * 入库-新建、编辑
	 **/
	@RequestMapping("/v1/editStockIn")
	@ResponseBody
	public ObjectResult<RProStockInBean> editStockIn(@Validated EditStockInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProStockInBean> res = new ObjectResult<RProStockInBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.editStockIn(param, request, response);
	}

	/**
	 * 入库-删除信息
	 **/
	@RequestMapping("/v1/delStockIn")
	@ResponseBody
	public BaseResult delStockIn(@Validated DelStockInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.delStockIn(param, request, response);
	}

	/**
	 * 入库-提交审核
	 **/
	@RequestMapping("/v1/submitStockIn")
	@ResponseBody
	public BaseResult submitStockIn(@Validated SubStockInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proStockController.submitStockIn(param, request, response);
	}
}
